package net.wofly.cashier.room.validator;

import net.wofly.cashier.room.domain.Room;
import net.wofly.cashier.room.util.RoomType;
import org.springframework.util.StringUtils;

/**
 * Desc:
 * Created by LiuJianbo on 2017/10/23.
 */
public class RoomValidator {

    /**
     * 换行符
     */
    private static String lineSeparator = System.getProperty("line.separator");

    public static String validateCommodityID(String commodityID) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(commodityID)) {
            stringBuffer.append("菜品ID不能为空！").append(lineSeparator);
        }
        return stringBuffer.toString();
    }

    public static String validateAddOrUpdateRoomParams(Room room, String employeeID, boolean validateKey) {
        StringBuffer stringBuffer = new StringBuffer();
        if (room == null) {
            stringBuffer.append("房间实体不能为空").append(lineSeparator);
        } else {
            if(validateKey){
                if (StringUtils.isEmpty(room.getRoomID())) {
                    stringBuffer.append("房间ID不能为空！").append(lineSeparator);
                }
            }
            if (StringUtils.isEmpty(room.getRoomCode())) {
                stringBuffer.append("房间编号不能为空！").append(lineSeparator);
            }
            if (StringUtils.isEmpty(room.getRoomName())) {
                stringBuffer.append("房间名称不能为空！").append(lineSeparator);
            }
            if (null == room.getRoomType() || !RoomType.isValueCorrect(room.getRoomType())) {
                stringBuffer.append("房间类型不能为空，或者房间类型的值不正确！").append(lineSeparator);
            }
        }
        if (StringUtils.isEmpty(employeeID)) {
            stringBuffer.append("员工ID不能为空！").append(lineSeparator);
        }
        return stringBuffer.toString();
    }

    public static String validateDelRoomParams(String roomID, String employeeID) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(roomID)) {
            stringBuffer.append("房间ID不能为空！").append(lineSeparator);
        }
        if (StringUtils.isEmpty(employeeID)) {
            stringBuffer.append("员工ID不能为空！").append(lineSeparator);
        }
        return stringBuffer.toString();
    }


    public static String validateGetAllRoomParams( String employeeID) {
        StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(employeeID)) {
            stringBuffer.append("员工ID不能为空！").append(lineSeparator);
        }
        return stringBuffer.toString();
    }
}
